<?php

/**
 * 主页布局
 */
namespace Admin\Controller;
use Think\Controller;
class HomePageListController extends InitController {

	//模板列表
	public function index(){
		$topmenu = $this->topmenu;
		$sidebarmenu = $this->sidebarmenu[I('get.k')];

		
		$merchant_id = 1;
		
		$list = M('LayoutList')->where(array('merchant_id' => $merchant_id))->select();

		$this->assign(array(
			'list' => $list,
		));
		$this->assign('topmenu',$topmenu);
		$this->assign('sidebarmenu',$sidebarmenu);
		$this->display('list');
	}


	//修改是否使用
	public function ChangeHomePage(){
		
		if ( IS_AJAX === false ) {
			$this->error('服务器提了一个问题！~');
		}

		$homepage_id = I('homepage_id');
		$merchant_id = I('merchant_id');

		if( $homepage_id !== false ){

			M('LayoutList')->where(array('is_default'=>1))->save(array('is_default'=>0));

			$num_rows = M('LayoutList')->where(array('homepage_id'=>$homepage_id))->save(array('is_default'=>1));
			if($num_rows > 0){
				$this->ajaxReturn(array('status'=>0,'msg'=>'更换成功'));
			}else{
				$this->ajaxReturn(array('status'=>1,'msg'=>'服务器提了一个问题！~'));
			}

		}
	}



}
